﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.IO;

namespace NetTopologySuite.Index.IntervalRTree
{
	public abstract class IntervalRTreeNode<T>
	{
		public double Min { get; protected set; }

		public double Max { get; protected set; }

		protected IntervalRTreeNode()
		{
			this.Min = double.PositiveInfinity;
			this.Max = double.NegativeInfinity;
		}

		protected IntervalRTreeNode(double min, double max)
		{
			this.Min = min;
			this.Max = max;
		}

		public abstract void Query(double queryMin, double queryMax, IItemVisitor<T> visitor);

		protected bool Intersects(double queryMin, double queryMax)
		{
			return this.Min <= queryMax && this.Max >= queryMin;
		}

		public override string ToString()
		{
			return WKTWriter.ToLineString(new Coordinate(this.Min, 0.0), new Coordinate(this.Max, 0.0));
		}

		public class NodeComparator : IComparer<IntervalRTreeNode<T>>
		{
			public int Compare(IntervalRTreeNode<T> n1, IntervalRTreeNode<T> n2)
			{
				double num = (n1.Min + n1.Max) / 2.0;
				double num2 = (n2.Min + n2.Max) / 2.0;
				if (num < num2)
				{
					return -1;
				}
				if (num > num2)
				{
					return 1;
				}
				return 0;
			}

			public static IntervalRTreeNode<T>.NodeComparator Instance = new IntervalRTreeNode<T>.NodeComparator();
		}
	}
}
